// componets/refreshScollView/index.js
const isIphoneX = wx.getSystemInfoSync().safeArea.top > 20 && wx.getSystemInfoSync().model.indexOf('iPhone') > -1 ? true : false

const _top = wx.getSystemInfoSync().statusBarHeight + 44
const _bottom = isIphoneX ? 102 : 55

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isRefresh:{
      type:Boolean,
      value:false
    },
    isNoMoreData:{
      type:Boolean,
      value:false
    },
    top:{
      type:Number,
      value:_top
    },
    bottom:{
      type:Number,
      value: _bottom
    },
    // black | white | none
    refreshStyle:{
      type:String,
      value:'black'
    },
    height:{
      type:Number,
      value: wx.getSystemInfoSync().screenHeight - _top - _bottom
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    extraHeight:500 
  },
  /***这种写法模拟器上不会调用,真机测试会调用**/
  observers:{
    'isRefresh': function (isRefresh) {
      this._freshing = isRefresh
      if(isRefresh === true){
         this.data.isNoMoreData = false
      }
    },
    'isNoMoreData':function(isNoMoreData){
      console.log('isNoMoreData:', isNoMoreData)
    },
    "top,bottom":function(top,bottom){
      this.setData({extraHeight:top + bottom})
      console.log('extraHeight:',this.data.extraHeight)
    }
  },

  attached(){
      this.setData({
        extraHeight: this.data.top + this.data.bottom
      })
  },
  /**
   * 组件的方法列表
   */
  methods: {

    refreshHeight(){
      

    },

    onLower() {
      this.triggerEvent('loadMore')
    },
    // 下来刷新被触发
    onRefresh() {
      if (this._freshing) return
      this._freshing = true
      this.triggerEvent('onRefresh')
    },
    // 自定义下拉刷新被复位
    onRestore(e) {
      console.log('onRestore:', e)
    },
    // 自定义下拉刷新被中止
    onAbort(e) {
      console.log('onAbort', e)
    }
    
  }
})
